package com.web44.spring.web;

import com.web44.spring.bean.Student;
import com.web44.spring.service.StudentService;
import com.web44.spring.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

/**
 * @Title: UserController
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2024/1/9 9:05
 */
@Controller
public class StudentController {

    @Autowired
    @Qualifier("s")
    private Student student;

    // 注入UserService
//    @Autowired // 通过类型注入 但是 StudentService 对应两个实现类  即为对应了两个bean
//    @Qualifier("abc")  // Qualifier 表示 指定类型中 要注入哪个名字的bean
    //  @Autowired  + @Qualifier 等价于 @Resource
    // @Qualifier("studentServiceClientImpl")
    @Resource(name="abc")
    private StudentService studentService;

//    @Autowired  // 写在set 上
//    public void setStudentService(StudentService studentService) {
//        this.studentService = studentService;
//    }

//    @Autowired  // 写在构造上
//    public StudentController(StudentService studentService) {
//        this.studentService = studentService;
//    }

     // 写在形参上
//    public StudentController(@Autowired StudentService studentService) {
//        this.studentService = studentService;
//    }




    // 只有一个构造函数 @Autowired  可以省略不写
//    public StudentController(StudentService studentService) {
//        this.studentService = studentService;
//    }

    public void queryUserWeb() {
        System.out.println(student);
        System.out.println("学生正在访问....");

        studentService.queryUserService();

    }
}
